package com.lpf.json.fastjson.SerializeFilter;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.PropertyFilter;

public class TestPropertyFilter {

	public static void main(String[] args) {
		PropertyFilter filter = new PropertyFilter() {

			@Override
			public boolean apply(Object source, String name, Object value) {

				System.out.println("----------------source=" + source);
				System.out.println("----------------name=" + name);
				System.out.println("----------------value=" + value);
				System.out.println("");

				if ("id".equals(name)) {
					long id = ((Long) value).longValue();
					return id >= 100;
				}
				return false;
			}
		};

		User user = new User();
		user.setId(9L);
		user.setName("挖坑埋你");

		String jsonString = JSON.toJSONString(user, filter); // 序列化的时候传入filter
		System.out.println("序列化,id=9：" + jsonString + "\n");

		user.setId(200L);
		jsonString = JSON.toJSONString(user, filter); // 序列化的时候传入filter
		System.out.println("序列化,id=200：" + jsonString);
	}

}
